package com.itheima.consumer.mp;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class SpringRabbitListener {

    @RabbitListener(queues = "simple.queue")
    public void mqListener1(String msg)
    {
        log.info("信息内容：{}",msg);
        throw new MessageConversionException("我是故意的");
    }
    @RabbitListener(queues = "work.queue")
    public void mqListener2(String msg) throws InterruptedException {
        System.out.println("11111"+msg);
        Thread.sleep(25);
    }
    @RabbitListener(queues = "work.queue")
    public void mqListener3(String msg) throws InterruptedException {

        System.err.println("22222"+msg);
        Thread.sleep(200);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void fanoutListener1(String msg) throws InterruptedException {
        System.out.println("11111fanout"+msg);
    }
    @RabbitListener(queues = "fanout.queue2")
    public void fanoutListener2(String msg) throws InterruptedException {

        System.err.println("22222fanout"+msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue1",durable = "true"),
            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT,durable = "true"),
            key = {"red","blue"}
    ))
    public void directListener1(String msg) throws InterruptedException {
        System.out.println("11111direct"+msg);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue2",durable = "true"),
            exchange = @Exchange(name = "hmall.direct",type = ExchangeTypes.DIRECT,durable = "true"),
            key = {"red","yellow"}
    ))
    public void directListener2(String msg) throws InterruptedException {
        System.out.println("22222direct"+msg);
    }

    @RabbitListener(queues = "topic.queue1")
    public void topicListener1(String msg) throws InterruptedException {
        System.out.println("11111topic"+msg);
    }
    @RabbitListener(queues = "topic.queue2")
    public void topicListener2(String msg) throws InterruptedException {

        System.err.println("22222topic"+msg);
    }


    @RabbitListener(queues = "object.queue")
    public void mqListener1(Map msg)
    {
        log.info("信息内容：{}",msg);
    }
}
